const statusDicData = [
	{ label: '已选择', value: 1, type: 'success' },
	{ label: '未选择', value: 0, type: 'info' },
]
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '补贴类型', prop: 'subsidyTypeLabel' },
		{ label: '名称', prop: 'applyConfigName' },
		{ label: '政策文件', prop: 'policyEnable', custome: 'tag', dicData: statusDicData },
		{ label: '申请表', prop: 'tableEnable', custome: 'tag', dicData: statusDicData },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const formateCallBackValue = (item, prop) => {
	const value = item[prop]
	if (!value) {
		return {}
	}
	let tempObj = {}
	const tempData = value && value.indexOf('{') !== -1 ? JSON.parse(value) : []
	let tempLabel = []
	let tempValue = []
	tempObj[`${prop}List`] = tempData.map((item, index) => {
		tempLabel[index] = item.label
		tempValue[index] = item.value
		return item
	})
	tempObj[`${prop}`] = tempValue.join(',')
	tempObj[`${prop}Label`] = tempLabel.join(',')
	return tempObj
}
export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '申请配置名称',
			prop: 'applyConfigName',
			type: 'input',
			span: 12,
			labelPosition: 'top',
			rules: [{ required: true, message: '请输入申请配置名称' }],
		},
		{
			label: '补贴类型',
			prop: 'subsidyType',
			propName: 'subsidyTypeLabel',
			type: 'remoteSelect',
			code: 'SUBSIDY_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			labelPosition: 'top',
			span: 12,
			rules: [{ required: true, message: '请选择补贴类型' }],
		},
		{
			label: '申请周期',
			prop: 'applyCycle',
			type: 'radio',
			dataType: 'number',
			custome: 'tag',
			dicData: [
				{ label: '月', value: 1 },
				{ label: '季度', value: 2 },
				{ label: '半年', value: 3 },
				{ label: '年', value: 4 },
				{ label: '一次性', value: 5 },
			],
			rules: [{ required: true, message: '请选择申请周期' }],
			span: 12,
		},
		{
			label: '申请时间(日)',
			prop: 'cycleDate',
			type: 'select',
			rules: [{ required: true, message: '请选择申请时间(日)' }],
			dicData: Array.from({ length: 31 }, (_, i) => ({ label: i + 1, value: `${i + 1}` })),
			span: 12,
		},
		{
			type: 'DividerHtml',
			modelValue: '政策文件',
			span: 24,
		},
		{
			label: '启用状态',
			prop: 'policyEnable',
			type: 'radio',
			dicData: [
				{ label: '启用', value: 1 },
				{ label: '关闭', value: 0 },
			],
			rules: [{ required: true, message: '请选择是否启用' }],
			control: (e, model) => {
				return {
					policyRel: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: '选择对应的补贴政策文件',
			prop: 'policyRel',
			propName: 'policyRelLabel',
			type: 'remoteSelect',
			paramsObj: {
				module: 2,
			},
			api: 'view_dpPolicyDocument_page',
			filterKey: 'id',
			filterLabel: 'policyTitle',
			multiple: true,
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '申请表',
			span: 24,
		},
		{
			label: '启用状态',
			prop: 'tableEnable',
			type: 'radio',
			rules: [{ required: true, message: '请选择是否启用' }],
			dicData: [
				{ label: '启用', value: 1 },
				{ label: '关闭', value: 0 },
			],
			control: (e, model) => {
				return {
					tableRel: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: '选择补贴适配动态表格',
			prop: 'tableRel',
			propName: 'tableRelLabel',
			type: 'remoteSelect',
			span: 24,
			multiple: true,
			rules: [{ required: true,trigger: 'change', message: '请选择申请需要的表格' }],
		},
	],
}

export const api = {
	index: 'view_ofsSubsidyApplyConfig_page',
	add: 'view_ofsSubsidyApplyConfig_add',
	edit: 'view_ofsSubsidyApplyConfig_edit',
	delete: 'view_ofsSubsidyApplyConfig_del',
	detail: 'view_ofsSubsidyApplyConfig_view',
}
export const baseConfig = {
	pageName: '申请表配置管理',
	dictcodes: ['COMMON_FLAG', 'SUBSIDY_TYPE', 'EQUIP_STATUS'],
	rowKey: 'id',
	tipLabel: 'applyConfigName',
	addLabel: '新增',
	exportMqTopic: '/ning/export/',
	paramsObj: {
		code: 3003,
	},
	api,
	auth: api,
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.detail,
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			icon: 'danger',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '80%',
	},
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '名称', prop: 'applyConfigName', type: 'input', span: 8 },

			{
				label: '是否选择政策文件',
				prop: 'policyEnable',
				type: 'remoteSelect',
				code: 'COMMON_FLAG',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '是否选择动态表格',
				prop: 'tableEnable',
				type: 'remoteSelect',
				code: 'COMMON_FLAG',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '补贴类型',
				prop: 'subsidyType',
				type: 'remoteSelect',
				code: 'SUBSIDY_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '是否选择动态表单',
				prop: 'materialEnable',
				type: 'remoteSelect',
				code: 'COMMON_FLAG',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '是否选择动态列表',
				prop: 'dataEnable',
				type: 'remoteSelect',
				code: 'COMMON_FLAG',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
		],
	},
	tableConfig,
	detailConfig: formConfig,
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			return {
				...item,
				...formateCallBackValue(item, 'tableRel'),
				...formateCallBackValue(item, 'policyRel'),
				...formateCallBackValue(item, 'materialRel'),
				...formateCallBackValue(item, 'dataRel'),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
